#include "AVLTree.h"
#include <vector>
void test1()
{
	real::AVLTree<int,int> at;
	at.Insert(std::make_pair(3, 3));
	cout<< at.Height(at.begin()) <<endl;
	at.Insert(std::make_pair(5, 5));
	cout << at.Height(at.begin()) << endl;
	at.Insert(std::make_pair(4, 4));
	cout << at.Height(at.begin()) << endl;
	at.Insert(std::make_pair(2, 2));
	cout << at.Height(at.begin()) << endl;
	at.Insert(std::make_pair(6, 6));
	cout << at.Height(at.begin()) << endl;
	at.Insert(std::make_pair(9, 9));
	cout << at.Height(at.begin()) << endl;
	at.Insert(std::make_pair(1, 1));
	cout << at.Height(at.begin()) << endl;
	at.Insert(std::make_pair(12, 12));
	at.Insert(std::make_pair(19, 19));
	at.Insert(std::make_pair(13, 13));
	at.Insert(std::make_pair(11, 11));

	at.InOrder();
	cout << "IsCorrectBf:" << at.IsCorrectBf() << endl;
	cout << "IsBalanceTree:" << at.IsBalanceTree() << endl;

	at.Erase(5);
	at.InOrder();
	cout << "IsCorrectBf:" << at.IsCorrectBf() << endl;
	cout << "IsBalanceTree:" << at.IsBalanceTree() << endl;
}

template<typename K, typename V>
void EraseTest(real::AVLTree<K, V> &at, const V& val)
{
	at.Erase(val);
	at.InOrder();
	cout << "Height:" << at.Height(at.begin()) << endl;
	cout << "IsCorrectBf:" << at.IsCorrectBf() << endl;
	cout << "IsBalanceTree:" << at.IsBalanceTree() << endl;
}

void test2()
{
	std::vector<int> a = { 6,2,3,7,5,9,1,26,16,14,12,84,62,18,77,36,68,66,72,15,47 };
	real::AVLTree<int, int> at;
	for (auto e : a)
	{
		at.Insert(std::make_pair(e, e));
	}
	at.InOrder();
	cout << "Height:" << at.Height(at.begin()) << endl;
	cout << "IsCorrectBf:" << at.IsCorrectBf() << endl;
	cout << "IsBalanceTree:" << at.IsBalanceTree() << endl;

	EraseTest(at, 62);
	EraseTest(at, 2);
	EraseTest(at, 18);
	EraseTest(at, 6);
	EraseTest(at, 3);
	EraseTest(at, 7);
	EraseTest(at, 5);
	EraseTest(at, 1);
	EraseTest(at, 12);
	EraseTest(at, 9);
	EraseTest(at, 14);
	EraseTest(at, 15);
	EraseTest(at, 16);
	EraseTest(at, 26);
	EraseTest(at, 36);
	EraseTest(at, 66);
	EraseTest(at, 68);
	EraseTest(at, 47);
	EraseTest(at, 84);
	EraseTest(at, 72);
	EraseTest(at, 77);
}

int main()
{
	//test1();
	test2();
	return 0;
}
